package cn.kust.serviceinterestpoint.controller;


import cn.kust.microtourismcommon.pojo.dto.ResponseResult;
import cn.kust.serviceinterestpoint.entity.InterestPicture;
import cn.kust.serviceinterestpoint.entity.vo.PictureAndVideoDTO;
import cn.kust.serviceinterestpoint.service.InterestPictureService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author microTourism
 * @since 2022-07-25
 */
@RestController
@RequestMapping("/serviceinterestpoint/interest-picture")
@Api(tags = "兴趣点图片模块")
public class InterestPictureController {

    @Autowired
    InterestPictureService pictureService;

    @PostMapping ("/save")
    @ApiOperation("添加兴趣点图片")
    public ResponseResult<Void> addPicture(InterestPicture picture){
        pictureService.save(picture);
        return ResponseResult.success("添加兴趣点图片成功");
    }

    @GetMapping("/delete/{id}")
    @ApiOperation("根据id删除兴趣点中的图片")
    @ApiImplicitParam(value = "删除图片的id",name="id",required = true, example = "1")
    public ResponseResult removePictureById(@PathVariable Long id){
        pictureService.removeById(id);
        return ResponseResult.success("图片已删除");
    }

    @GetMapping("/list/{interestId}")
    @ApiOperation("根据兴趣点id返回他的所有图片")
    @ApiImplicitParam(value = "兴趣点id",name="interestId",required = true, example = "1")
    public ResponseResult<List<PictureAndVideoDTO>> getAllPictures(@PathVariable Long interestId){
        List<PictureAndVideoDTO> interestPictures = pictureService.getAllPicturesByInterestId(interestId);
        return ResponseResult.success(interestPictures);
    }
}

